import Vue from 'vue'
import VueRouter from 'vue-router'


import login from './Login'
import home from './Home'



Vue.use(VueRouter)

const routes = [
  { path:'/', redirect:'/login'},
  login,
  home,
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next)=>{
  if(to.path == '/login') return next()
  const token = window.sessionStorage.getItem('token')
  if( !token ) return next('/login')
  next()
})

export default router
